//
//  LoginVC+UI.swift
//  Auscultation
//
//  Created by 来 on 2020/11/28.
//

import Foundation

extension LoginVC {
    
    func initUI() {
        view1 = UIImageView.init(image: #imageLiteral(resourceName: "login_header1@1.5x"))
        view.addSubview(view1)
        view1.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(view.lgf_Width * 0.7)
        }
        view2 = UIImageView.init(image: #imageLiteral(resourceName: "login_header2@1.5x"))
        view.addSubview(view2)
        view2.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(view.lgf_Width * 0.7)
        }
        
        dl_label = UILabel.init()
        dl_label.text = "登录"
        dl_label.font = UIFont.boldSystemFont(ofSize: 18)
        dl_label.isUserInteractionEnabled = true
        dl_label.lgf_AddTap(target: self, action: #selector(LoginVC.denglu))
        view.addSubview(dl_label)
        dl_label.snp.makeConstraints { (make) in
            make.top.equalTo(view1.snp.bottom).offset(20)
            make.height.equalTo(40.lgf_H())
            make.centerX.equalToSuperview().multipliedBy(0.565)
        }
        
        zc_label = UILabel.init()
        zc_label.text = "注册"
        zc_label.font = UIFont.boldSystemFont(ofSize: 18)
        zc_label.isUserInteractionEnabled = true
        zc_label.lgf_AddTap(target: self, action: #selector(LoginVC.zhuce))
        view.addSubview(zc_label)
        zc_label.snp.makeConstraints { (make) in
            make.top.equalTo(view1.snp.bottom).offset(20)
            make.height.equalTo(40.lgf_H())
            make.centerX.equalToSuperview().multipliedBy(1.435)
        }
        // 12345678901 xyadmin@v2
        yhm = LGFLoginImageTitleView.init(#imageLiteral(resourceName: "yonghuming@1.5x"), nil, left: 0, placeholder: "用户名/手机号/账号", text: "", false)
        yhm.delegate = self
        view.addSubview(yhm)
        yhm.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(32.lgf_W())
            make.right.equalToSuperview().offset(-32.lgf_W())
            make.top.equalTo(dl_label.snp.bottom).offset(15.lgf_H())
            make.height.equalTo(44.lgf_H())
        }
        
        mm = LGFLoginImageTitleView.init(#imageLiteral(resourceName: "mima@1.5x"), nil, left: 0, placeholder: "密码", text: "", false)
        mm.delegate = self
        mm.textField.isSecureTextEntry = true
        view.addSubview(mm)
        mm.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(32.lgf_W())
            make.right.equalToSuperview().offset(-32.lgf_W())
            make.top.equalTo(yhm.snp.bottom).offset(15.lgf_H())
            make.height.equalTo(44.lgf_H())
        }
        
        yzm = LGFLoginImageTitleView.init(#imageLiteral(resourceName: "yanzhengma@1.5x"), nil, left: 0, placeholder: "输入验证码", text: "", false)
        yzm.delegate = self
        view.addSubview(yzm)
        yzm.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(32.lgf_W())
            make.right.equalToSuperview().offset(-32.lgf_W())
            make.top.equalTo(mm.snp.bottom).offset(15.lgf_H())
            make.height.equalTo(44.lgf_H())
        }
        
        let hqyzm = UIButton.init(type: .custom)
        hqyzm.setTitle("获取验证码", for: .normal)
        hqyzm.setTitleColor(UIColor.init(lgf_HexString: "0F88F2"), for: .normal)
        hqyzm.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        hqyzm.layer.cornerRadius = 5
        hqyzm.layer.borderColor = UIColor.init(lgf_HexString: "0F88F2")?.cgColor
        hqyzm.layer.borderWidth = 1
        hqyzm.addTarget(self, action: #selector(LoginVC.yanzhengma(_:)), for: .touchUpInside)
        yzm.addSubview(hqyzm)
        hqyzm.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().offset(-10)
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(90)
        }
        
        retPwdBtn = UIButton.init(type: .custom)
//        retPwdBtn.backgroundColor = UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!
        retPwdBtn.setTitle("重置密码", for: .normal)
        retPwdBtn.setTitleColor(EWEDarkMode.black(), for: .normal)
        retPwdBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        retPwdBtn.titleLabel?.textAlignment = .left
        retPwdBtn.layer.cornerRadius = 8
        retPwdBtn.layer.masksToBounds = true
        retPwdBtn.addTarget(self, action: #selector(LoginVC.retPwdBtn(_:)), for: .touchUpInside)
        view.addSubview(retPwdBtn)

        
        loginBtn = UIButton.init(type: .custom)
        loginBtn.backgroundColor = UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!
        loginBtn.setTitle("登陆", for: .normal)
        loginBtn.setTitleColor(EWEDarkMode.white(), for: .normal)
        loginBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        loginBtn.layer.cornerRadius = 8
        loginBtn.layer.masksToBounds = true
        loginBtn.addTarget(self, action: #selector(LoginVC.login(_:)), for: .touchUpInside)
        view.addSubview(loginBtn)
        
        retPwdBtn.snp.makeConstraints { (make) in
            make.left.equalTo(loginBtn)
            make.bottom.equalTo(loginBtn.snp.top).offset(-10)
            make.height.equalTo(44.lgf_H())
        }

        loginBtn.snp.makeConstraints { (make) in
            make.top.equalTo(yzm.snp.bottom).offset(35.lgf_H())
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-80.lgf_W())
            make.height.equalTo(44.lgf_H())
        }
    }

}

extension LoginVC: LGFLoginImageTitleViewDelegate {
    func selectLGFLoginImageTitleView(_ view: LGFLoginImageTitleView) {
        self.view.endEditing(true)
        
    }
}
